﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Entities;
using ExpertMIS.Brokers;
using System.Collections;

namespace ExpertMIS.Admin.UserControl
{
    public partial class DomainForm : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public DomainEntity Entity
        {
            get
            {
                return ViewState["_" +GetType().ToString() + "_"] as DomainEntity;
            }
            set
            {
                ViewState["_" + GetType().ToString() + "_"] = value;
            }
        }

        public void LoadDomain(string DomainOID)
        {
            DomainBroker broker = new DomainBroker();

            Hashtable htQuery = new Hashtable();
            htQuery["OID"] = DomainOID;
            Entity = broker.GetEntity(htQuery) as DomainEntity;

            if (Entity == null)
            {
                Entity = broker.NewEntity() as DomainEntity;
            }
            else
            {
                txName.Text = Entity.DomainName;
                txRemark.Text = Entity.Remark;
                txLocation.Text = Entity.Location;
            }
        }

        public bool SaveDomain()
        {
            try
            {
                DomainBroker broker = new DomainBroker();

                Entity.DomainName = txName.Text;
                Entity.Remark = txRemark.Text;
                Entity.Location = txLocation.Text;

                broker.SaveEntity(Entity, null);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}